package com.baizhi.service.impl;

import com.baizhi.annolation.LogAnnotation;
import com.baizhi.dao.UserDao;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    @LogAnnotation(type = "用户模块",value="修改用户状态为激活/冻结/解冻")
    public void update(Integer status, Integer id) {
        //如果未激活  点击激活
        if(status==0){
            userDao.toLive(id);
            System.out.println("账号已激活");
            //如果激活  点击冻结
        }else if (status==2){
            userDao.toDie(id);
            System.out.println("账号已冻结");
            //如果冻结去激活
        }else if (status==3){
            userDao.toLive(id);
            System.out.println("账号已解冻");
        }
    }

    @Override
    @LogAnnotation(type = "用户模块",value="查询所有的用户信息")
    public Map selectAllUser(Integer page, Integer limit) {
        Map map=new HashMap();
        Integer offset=(page-1)*limit;
        List<User> users = userDao.selectAllUser(offset, limit);
        int i = userDao.countUser();
        map.put("data",users);
        map.put("msg","");
        map.put("code",0);
        map.put("count",i);
        return  map;
    }

    @Override
    @LogAnnotation(type = "用户模块",value="删除用户信息")
    public void deleteUser(Integer id) {
        userDao.deleteUser(id);
    }

    @Override
    @LogAnnotation(type = "用户模块",value="批量添加用户")
    public void insertMore(List<User> userList) {
        userDao.insertMore(userList);
    }
}
